package com.example.demo.test;

import com.example.demo.consumer.Consumer;
import com.example.demo.producer.Producer;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;

import java.util.concurrent.*;

/**
 * @author: wukangrong
 * @date: 2020/4/22 14:13
 * @description:
 */
public class Main {
    public static void main(String[] args) {
//        Consumer con = new Consumer("消费者一号");
//        Producer pro = new Producer("生产者一号");
//        con.start();
//        pro.start();
        ThreadFactory consumerFactory = new CustomizableThreadFactory("消费者-");
        ExecutorService consumerExecutor = new ThreadPoolExecutor(2, 10,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(10),consumerFactory);

        ThreadFactory producerFactory = new CustomizableThreadFactory("生产者-");
        ExecutorService producerExecutor = new ThreadPoolExecutor(2, 10,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(10),producerFactory);
        consumerExecutor.execute(new Consumer());
        producerExecutor.execute(new Producer());
        producerExecutor.execute(new Producer());
    }
}
